<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="/pages/sysIndex/default.jsp"/>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-trophy"></i> 点位管理
            </div>
            <div class="box-tools pull-right">
                <a href="#" class="btn btn-default" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
                <a href="javascript:;" onclick="vLayuiUtil.openLayerWindow('wWuHanPoint', '<c:url value="/web/wuhan/point/getPointEditPage.action"/>','新增')" class="btn btn-default btnTool" title="新增权限"><i class="fa fa-plus"></i> 新增</a>
                <div class="btn-group">
                    <a href="javascript:" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                        <i class="fa fa-navicon"></i> <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a href="javascript:" id="btnExport"><i class="glyphicon glyphicon-export"></i> 导出</a></li>
                        <li><a href="javascript:" id="btnImport"><i class="glyphicon glyphicon-import"></i> 导入</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="box-body">
            <form id="searchForm" action="<c:url value="/web/wuhan/point/getPointListJSON.action"/>" method="post" class="form-inline hide" data-page-no="1" data-page-size="20" data-order-by="">
                <div class="form-group">
                    <label class="control-label">搜索：</label>
                    <div class="control-inline">
                        <input type="text" id="searchCode" name="searchCode" value="" maxlength="64" class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">查询</button>
                    <button type="reset" class="btn btn-default btn-sm">重置</button>
                </div>
            </form>

            <table id="dataGrid"></table>
            <div id="dataGridPage"></div>
        </div>
    </div>
</div>
<script>
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        shrinkToFit: false,
        autoScroll: true,
        columnModel: [
            {header:'点位', name:'name', index:'name', width:300, align:"center"},
            {header:'备注', name:'remark', index:'remark', width:300, align:"center"},
            {header:'单位', name:'unitOfMeasurement', index:'unitOfMeasurement', width:300, align:"center"},
            {header:'设备', name:'unit', index:'unit', width:300, align:"center",sortable: false},
            {header:'机组', name:'meterReadingName', index:'meterReadingName', width:300, align:"center",sortable: false},
            {header:'系统', name:'pointSystemName', index:'pointSystemName', width:300, align:"center",sortable: false},
            {header:'创建时间', name:'createDate', index:'createDate', width:300, align:"center"},
            {
                header: '操作',
                name: 'actions',
                width: 150,
                sortable: false,
                title: false,
                formatter: function (val, obj, row, act) {
                    var editUrl='<c:url value="/web/wuhan/point/getPointEditPage.action?pointId="/>'+row.pointId;
                    var result='<a href="javascript:;" class="btn btn-default btn-xs btnList" onclick="vLayuiUtil.openLayerWindow(\'wWuHanPoint\', \''+editUrl+'\',\'编辑\')"><i class="fa fa-pencil">编辑</i></a>&nbsp;';
                    result+='<a href="javascript:;" class="btn btn-default btn-xs btnList" title="删除" onclick="del(\''+row.pointId+'\')"><i class="fa fa-trash-o">删除</i></a>&nbsp;';
                    return result;
                }
            }
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });

    function del(id) {
        js.confirm('你确认要删除这条数据吗？',function () {
            $.ajax({
                type: 'POST',
                url: "<c:url value="/web/wuhan/point/logicRemoveWuHanPoint.action"/>",
                data: {
                    pointId: id
                },
                dataType: 'json',
                async: false,
                error: function (data) {
                    js.showErrorMessage(data.responseText);
                },
                success: function (data, status, xhr) {
                    js.showMessage(data.msg);
                    if(data.status == Global.NO){
                        $('#dataGrid').dataGrid("refresh");
                    }
                }
            });
        });
    }

    $('#btnImport').click(function(){
        js.layer.open({
            type: 1,
            area: ['400px'],
            title: '导入数据',
            resize: false,
            scrollbar: true,
            content: js.template('importTpl'),
            success: function(layero, index){
                // layero.find('input[type="checkbox"]').iCheck();
            },
            btn: ['<i class="fa fa-check"></i> 导入',
                '<i class="fa fa-remove"></i> 取消'],
            btn1: function(index, layero){
                var form = {
                    inputForm: layero.find('#inputForm'),
                    file: layero.find('#file').val()
                };
                if (form.file == '' || (!js.endWith(form.file, '.xls') && !js.endWith(form.file, '.xlsx'))){
                    js.showMessage("文件不正确，请选择后缀为 “xls”或“xlsx”的文件。", null, 'warning');
                    return false;
                }
                js.ajaxSubmitForm(form.inputForm, function(data){
                    console.log(data);
                    js.showMessage(data.msg);
                    if(data.status == Global.NO){
                        js.layer.closeAll();
                    }
                    page();
                }, "json");
                return true;
            }
        });
    });

    $('#btnExport').click(function(){
        js.ajaxSubmitForm($('#searchForm'), {
            url:'<c:url value="/web/wuhan/point/exportData.action"/>',
            downloadFile:true
        });
    });
</script>

<script id="importTpl" type="text/template">
<form id="inputForm" action="<c:url value="/web/wuhan/point/importData.action"/>" method="post" enctype="multipart/form-data"
	class="form-horizontal mt20 mb10" style="overflow:auto;max-height:200px;">
	<div class="row">
		<div class="col-xs-12 col-xs-offset-1">
			<input type="file" id="file" name="file" class="form-file"/>
			<div class="mt10 pt5">
				<a href="<c:url value="/resources/file/point.xls"/>" download="点位数据模板.xls" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
			</div>
			<font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
			</font>
		</div>
	</div>
</form>
</script>